<script>
	import {
		loginUser2
	} from 'api/user.js'
	import { getAccessToken } from 'api/getAccessToken.js'
	export default {
		created() {
			this.tokenlistenner()
			// setInterval(()=>{
			// 	this.tokenlistenner()
			// },2000)
			this.getAccessToken()
		},
		methods:{
			async tokenlistenner(){
				const token = uni.getStorageSync('token')
				if (token) {
					const res = await loginUser2()
					console.log(res)
					if (res.statusCode == 200) {
						uni.setStorageSync('token', res.data.data.token)
						this.$store.commit('initUserInfo', res.data.data)
					}
					if (res.statusCode == 804) {
						uni.removeStorageSync('token')
						uni.showModal({
							title: '已在其他设备登录',
							content: '点击确定将返回登录页面',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url:'/pages/login/login'
									})
								}
							}
						});
				
					}
				}
			},
			async getAccessToken() {
				const { data: { data: { accessToken } } } = await getAccessToken()
				this.$store.commit('saveAccessToken', accessToken)
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@font-face {
		font-family: 'icomoon';
		src: url('~@/static/fonts/icomoon.eot?5ir889');
		src: url('~@/static/fonts/icomoon.eot?5ir889#iefix') format('embedded-opentype'),
			url('~@/static/fonts/icomoon.ttf?5ir889') format('truetype'),
			url('~@/static/fonts/icomoon.woff?5ir889') format('woff'),
			url('~@/static/fonts/icomoon.svg?5ir889#icomoon') format('svg');
		font-weight: normal;
		font-style: normal;
		font-display: block;
	}

	[class^="icon-"],
	[class*=" icon-"] {
		/* use !important to prevent issues with browser extensions that change fonts */
		font-family: 'icomoon' !important;
		speak: never;
		font-style: normal;
		font-weight: normal;
		font-variant: normal;
		text-transform: none;
		line-height: 1;

		/* Better Font Rendering =========== */
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.icon-email:before {
	  content: "\e917";
	}
	.icon-checkmark-outline:before {
	  content: "\e910";
	}
	.icon-cheveron-down:before {
	  content: "\e900";
	}
	.icon-cheveron-left:before {
	  content: "\e901";
	}
	.icon-cheveron-right:before {
	  content: "\e902";
	}
	.icon-cheveron-up:before {
	  content: "\e903";
	}
	.icon-location1:before {
	  content: "\e905";
	}
	.icon-location-current:before {
	  content: "\e906";
	}
	.icon-menu:before {
	  content: "\e907";
	}
	.icon-network:before {
	  content: "\e908";
	}
	.icon-search:before {
	  content: "\e909";
	}
	.icon-window:before {
	  content: "\e90b";
	}
	.icon-user:before {
	  content: "\e911";
	}
	.icon-view-show:before {
	  content: "\e916";
	}
	.icon-apple:before {
	  content: "\e90a";
	  color: #999;
	}
	.icon-hand:before {
	  content: "\e90d";
	}
	.icon-accessibility:before {
	  content: "\e90d";
	}
	.icon-info1:before {
	  content: "\e90c";
	}
	.icon-qr_code_2:before {
	  content: "\e913";
	}
	.icon-qr_code_scanner:before {
	  content: "\e914";
	}
	.icon-qr_code:before {
	  content: "\e915";
	}
	.icon-home:before {
	  content: "\e904";
	}
	.icon-cart:before {
	  content: "\e93a";
	}
	.icon-location:before {
	  content: "\e947";
	}
	.icon-camera:before {
	  content: "\e90f";
	}
	.icon-history:before {
	  content: "\e94d";
	}
	.icon-bubbles3:before {
	  content: "\e96f";
	}
	.icon-user-check:before {
	  content: "\e975";
	}
	.icon-cog:before {
	  content: "\e994";
	}
	.icon-cloud-check:before {
	  content: "\e9c4";
	}
	.icon-info:before {
	  content: "\ea0c";
	}
	.icon-exit:before {
	  content: "\ea14";
	}
	.icon-loop2:before {
	  content: "\ea2e";
	}
	.icon-cancel-circle:before {
	  content: "\ea0d";
	}
	.icon-circle-up:before {
	  content: "\ea41";
	}
	.icon-circle-right:before {
	  content: "\ea42";
	}
	.icon-circle-down:before {
	  content: "\ea43";
	}
	.icon-circle-left:before {
	  content: "\ea44";
	}
	.icon-radio-unchecked:before {
	  content: "\ea56";
	}
	.icon-info2:before {
	  content: "\ea0e";
	}
	.icon-envelop:before {
	  content: "\e945";
	}
	.icon-eye:before {
	  content: "\e9ce";
	}
	.icon-eye-blocked:before {
	  content: "\e9d1";
	}
	.icon-handshake-o:before {
	  content: "\e90e";
	}
	.icon-qq:before {
	  content: "\e912";
	}
</style>
